﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ServiceModel;

using YLPublicService;
using YLClient.Config;
using YLPublicService.TransferModel;
namespace YLClient.YLServiceClient
{
    class ServiceClient : ClientBase<IUserService>
    {
        private ServiceClient()
            : base()
        {
            loginSuccessGuid = Guid.Empty;
        }
        static ServiceClient client;
        static object sync = new object();
        public static ServiceClient GetServiceClient()
        {
            if (client == null)
            {
                lock (sync)
                {
                    client = new ServiceClient();
                }
            }
            return client;
        }

        private Guid loginSuccessGuid;
        private FtpServerInfo ftpServerInfo;
        #region 封装服务提供的方法
        public FtpServerInfo RequestFtpServerInfo(bool reGetFtpServerInfo)
        {
            if (reGetFtpServerInfo || ftpServerInfo == null)
            {
                ftpServerInfo = this.Channel.RequestFtpServerInfo(loginSuccessGuid);
            }
            return ftpServerInfo;
        }

        public string GetFinishFileServerPath(int workItemID)
        {
            return this.Channel.GetFinishFileServerPath(workItemID, loginSuccessGuid);

        }

        public UserAccount GetAccount()
        {
            return this.Channel.GetAccount(loginSuccessGuid);

        }

        public DateTime[] GetUserWorkItemDates()
        {
            return this.Channel.GetUserWorkItemDates(loginSuccessGuid);

        }

        public IEnumerable<WorkItem> GetWorkItems()
        {

            return this.Channel.GetWorkItems(loginSuccessGuid);


        }

        public IEnumerable<WorkItem> GetWorkItems(DateTime start, DateTime end)
        {
            return this.Channel.GetWorkItems(start, end, loginSuccessGuid);

        }

        public int AddWorkItem(WorkItem item)
        {
            return this.Channel.AddWorkItem(item, loginSuccessGuid);

        }

        public bool UpdatedWorkItemStatus(WorkItem item, WorkItemStatus newStatus)
        {
            return this.Channel.UpdatedWorkItemStatus(item, newStatus, loginSuccessGuid);

        }

        public WorkItem[] GetFinishWorkItems(DateTime start, DateTime end)
        {
            return this.Channel.GetFinishWorkItems(start, end, loginSuccessGuid);

        }

        public Guid Login(string loginName, string pwd)
        {

            loginSuccessGuid = this.Channel.Login(loginName, pwd);
            return loginSuccessGuid;

        }

        public void LoginOut()
        {
            this.Channel.LoginOut(loginSuccessGuid);
        }

        public TemplateItem[] GetEnableTemplates()
        {
            return this.Channel.GetEnableTemplates(loginSuccessGuid);
        }
        #endregion
    }
}
